//
//  UserIconAndNameView.m
//  OnionHome
//
//  Created by fengjie on 2019/9/16.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "UserIconAndNameView.h"
#import "OneToastController.h"
#import "PersonalHomePageBasseController.h"


@interface UserIconAndNameView ()

@end

@implementation UserIconAndNameView
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self layoutIfNeeded];
        [self createUI];
    }
    return self;
}
-(void)createUI{
    [self addSubview:self.iconImage];
    [self addSubview:self.userName];
    [self addSubview:self.dynamicData];
    [self addSubview:self.deleButton];
    
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.width.height.mas_equalTo(40);
        make.bottom.mas_equalTo(-16);
    }];
    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImage.mas_right).offset(12);
        make.top.mas_equalTo(self.iconImage).offset(2);
    }];
    [self.dynamicData mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImage.mas_right).offset(12);
        make.top.mas_equalTo(self.userName.mas_bottom).offset(4);
    }];
    [self.deleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.iconImage);
//        make.width.height.mas_equalTo(14);
    }];
    [self.deleButton sizeToFit];
}

/// 进入用户个人中心页面
-(void)pushUserContenPage{
    PersonalHomePageBasseController * vc = [[PersonalHomePageBasseController alloc] init];
    vc.type = PersonalHomePageTA;
    [[self getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
#pragma mark --懒加载

-(UIImageView*)iconImage{
    if(!_iconImage){
        _iconImage=[[UIImageView alloc] init];
        _iconImage.layer.cornerRadius = 20;
        _iconImage.image = IMAGE_NAMED(@"userIconDefut");
        _iconImage.image = IMAGE_NAMED(@"user5");
        _iconImage.layer.masksToBounds = YES;
        _iconImage.userInteractionEnabled = YES;
        [_iconImage addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushUserContenPage)]];
    }
    return _iconImage;
}
-(UILabel*)userName{
    if(!_userName){
        _userName=[UILabel new];
        _userName.font = BOLDSYSTEMFONT(14);
        _userName.textColor = UIColorFromRGB(0x273323);
        _userName.text = @"我是大鲨鱼";
        _userName.userInteractionEnabled = YES;
        [_userName addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushUserContenPage)]];
    }
    return _userName;
}
-(UILabel*)dynamicData{
    if(!_dynamicData){
        _dynamicData=[UILabel new];
        _dynamicData.font = SYSTEMFONT(12);
        _dynamicData.textColor = UIColorFromRGB(0x959E97);
        _dynamicData.text = @"昨天 14:15";

    }
    return _dynamicData;
}
-(UIButton*)deleButton{
    if(!_deleButton){
        _deleButton=[UIButton buttonWithType:UIButtonTypeCustom];
        [_deleButton setBackgroundImage:IMAGE_NAMED(@"icon_quxiao") forState:UIControlStateNormal];
        kWeakSelf(weakSelf);
        [_deleButton addActionHandler:^{
            PresentationObject * object = [PresentationObject sharedPresentationObject];
            CGFloat y = (KScreenHeight - 290)/2;
//            object.alpha_bgView = 0.3;
            object.subViewFrame =CGRectMake(20, y, KScreenWidth-40, 290);
            OneToastController * vc = [OneToastController new];
            [object showPresentingViewController:[weakSelf getCurrentViewController] PresentedViewController:[[BasseNavigationController alloc]initWithRootViewController:vc]];
            vc.notInterestedBlock = ^{
                
            };
            
        }];
    }
    return _deleButton;
}
@end
